export default {
  data() {
    return {
      setAsDefault: false, //设置默认
      schemeType: '以租代售', //方案类型
      schemeName: '以租代售 黑户专用-1', //方案名称
      upfloclick: true, //true展开收起false
      checkClick: false, //选中
      data: {
        List: [{
          'Id': 'string',
          'Name': 'string', //名称
          'LoanPlan_Type': 0, //分类（0低首付，1以租代售）
          'Is_Default': 0, //默认标识(0关闭，1打开)
          'PlanTotal': 0, //方案组总条数
          'PlanList': [{ //方案组分组列表
            'Proportion': 0, //首付比例
            'LoanPlan_PlanList': [{ //方案组列表
              'Proportion': 0, //首付比例
              'LoanPeriods': 0, //贷款期数
              'InterestRate': 0, //贷款利率(如果不填则是-1)
              'Poundage': 0 //金融手续费(如果不填则是-1)
            }]
          }]
        }],
        'Total': 0, //总条数
        'CurrentPage': 0 //当前页
      },
      dataTable: [{
        'qishu': '12',
        'lilv': '输入',
        'shouxu': '输入2',
      }, {
        'qishu': '24',
        'lilv': '输入',
        'shouxu': '输入2',
      }, {
        'qishu': '36',
        'lilv': '输入',
        'shouxu': '输入2',
      }, {
        'qishu': '48',
        'lilv': '输入',
        'shouxu': '输入2',
      }, {
        'qishu': '60',
        'lilv': '输入',
        'shouxu': '输入2',
      }],
      defaultMap: false, //默认图
      fAType: 0, //0低首付1金融方案
      pageskulist: [],
      dishoufu: [{
        name: '低首付',
        value: 0
      }, {
        name: '以租代售',
        value: 1
      }],
      financialSolution: 0, //金融方案id
      finasname: '', //金融方案name

      fanganid: '', //方案id
      fanganleix: null, //方案类型
      moneynum: null, //裸车价
      Lengexpansion: 0, //展开的长度
      showPage: false
    }
  },
  onLoad(carvule) {
    this.fAType = Number(carvule.type)
    this.moneynum = Number(carvule.moneynum) * 10000
    if (this.moneynum === 0) {
      this.moneynum = null
    }
    // 0低首付1金融方案
  },
  onShow() {
    this.GetLoanOlanDataList()
  },
  created() {},
  methods: {
    //获取金融方案列表
    async GetLoanOlanDataList() {
      try {
        let data = {
          'PageIndex': 1,
          'PageSize': 10,
          'Loanplan_Type': this.fAType, //方案类型（分类（0低首付，1以租代售））
          'Store_Id': this.$store.state.userInfoDetail.store.storeId,
          'Client_price': this.moneynum
        }
        const res = await this.$api.carSource.GetLoanOlanDataList(data)
        this.pageskulist = [] //清空数据
        if (res.code === 200) { //返回成功
          this.pageskulist = res.data.list //请求成功赋值
          if (this.pageskulist.length === 0) {
            //数据为空，true显示默认图false隐藏默认图
            this.defaultMap = true
          } else {
            this.defaultMap = false
          }

          let listbox = [] //暂存赋值
          this.pageskulist.forEach((item, i) => {
            item.upfloclick = true
            item.zhankai = '展开'
            listbox.push(item)
            item.planList.forEach(item1 => {
              item1.Lengexpansion = item1.loanPlan_PlanList.length
            })

          })
          this.pageskulist = listbox

          this.showPage = true
          // 设置默认方案
          this.pageskulist.forEach(item => {
            item.is_Default = item.is_Default === 1 ? true : false
          })
          console.log(this.pageskulist)

        }
      } catch (err) {
        console.log(err)
      }
    },
    getType(type) {
      let result = ''
      this.dishoufu.forEach(it => {
        if (it.value === type) {
          result = it.name
        }
      })
      this.finasname = result
      return result
    },
    // 返回
    fanhui() {
      //图片地址
      uni.$emit('carImageS', {
        carImageS: this.carImageS
      })
      uni.navigateBack()
      uni.$off('currentImgs')
    },
    switcclick(type, index) {
      this.fanganid = type.id
      this.fanganleix = type.loanPlan_Type
      this.DeleteLoanOlanDefault()
    },
    //设置默认方案
    async DeleteLoanOlanDefault() {
      try {
        let data = {
          'LoanPlan_type': this.fanganleix, //分类（0低首付，1以租代售）
          'Id': this.fanganid, //方案id
          'Store_Id': this.$store.state.userInfoDetail.store.storeId
        }
        const res = await this.$api.carSource.DeleteLoanOlanDefault(data)
        if (res.code === 200) { //返回成功
          this.GetLoanOlanDataList()
          setTimeout(function() {
            uni.showToast({
              title: '设置成功',
              duration: 2000,
              icon: 'none'
            })
          }, 100)
          // uni.navigateBack()
        }
      } catch (err) {
        console.log(err)
      }
    },
    //点击展开收起
    upClick(type) {
      this.upfloclick = !this.upfloclick

      let listbox = [] //暂存赋值
      this.pageskulist.forEach((item, i) => {
        if (i === type) {
          if (item.upfloclick === false) {
            item.upfloclick = true //设置默认方案
            item.zhankai = '展开' //设置默认方案
          } else {
            item.zhankai = '收起' //设置默认方案
            item.upfloclick = false //设置默认方案
          }
        } else {}
        listbox.push(item)
      })
      this.pageskulist = listbox
      // console.log(this.pageskulist)

      // this.pageskulist.forEach(item => {
      //   item.zhankai = item.is_Default === 1 ? true : false
      // })
    },
    //勾选中
    cheCllickz(itemss, index) {
      let listbox = []
      if (itemss.chekdfalse === false) {
        itemss.chekdfalse = true
      } else {
        itemss.chekdfalse = false
      }
      this.financialSolution = itemss.id //金融id

      if (this.fAType === 0) {
        //存储金融id
        uni.$emit('financialSolution', {
          fsid: itemss.id,
          fsname: this.finasname,
          name: itemss.name
        })
      } else {
        //存储金融id
        uni.$emit('yzdsclicklist', {
          yzdsid: itemss.id,
          yzdsname: this.finasname,
          name: itemss.name
        })
      }

      this.pageskulist[index] = itemss
      this.$set(itemss, index, true)
      console.log(this.pageskulist)
      uni.navigateBack()
      // item.chekdfalse = !item.chekdfalse
    },
    // 新增金融
    newFinanSClick() {
      uni.navigateTo({
        url: '/pages_carSource/newFinancialSolution/newFinancialSolution?type=' + this.fAType + '&moneynum=' + this
          .moneynum
      })
    },
    //跳转编辑
    editclick(listtype) {
      uni.navigateTo({
        url: '/pages_carSource/editFinancialSolution/editFinancialSolution?datalist=' + encodeURIComponent(JSON.stringify(
          listtype)) + '&moneynum=' + this.moneynum
      })
    },
  }
}
